package mspbots.data.sync.converter;

import cn.hutool.json.JSONUtil;
import io.r2dbc.postgresql.codec.Json;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;
import org.springframework.lang.Nullable;

import java.util.Set;
import java.util.stream.Collectors;

/**
 * com.mspbots.web.security.converter.UserReadConverter
 *
 * @author Alex bob(https://github.com/vnobo)
 * @date Created by 2019/12/17
 */

@ReadingConverter
public class SetReadConverter implements Converter<Json, Set<Object>> {

    @Nullable
    @Override
    public Set<Object> convert(Json source) {
        return JSONUtil.parseArray(source.asString()).toList(String.class).parallelStream().collect(Collectors.toSet());
    }
}
